<?php 

class ConnexionController extends Zend_Controller_Action
{ 
	public function deconnexionAction(){
		session_unset($_SESSION['isConnect']);
		$this->_redirect('/');
	}
	
	public function connexionAction()
    {
    	$form = new Form_Connexion();
    	if($this->getRequest()->isPost()){
    		if ($form->isValid($this->getRequest()->getPost())){
    			$values = $form->getValues();
    			if($this->verifIdentifiantAction($values["login"], $values["pass"])==$values["login"]){
    				$_SESSION['isConnect'] = $values["login"];
    				$this->_redirect('/');
    			}else {
    				$this->view->form = $form;
    			}
    		}
    	}
    	$this->view->form = $form; 
    }
    
    public function verifIdentifiantAction($login, $pass){
    	$parametres = new Table_Parametres();
    	$user = $parametres->getUtilisateurByLogin($login);
    	$resu = null;
    	if(!is_null($user)){
    		if ($parametres->encryptPasswd($pass)==$user->PASSWD){
    			$resu = $login;
    		}
    	}
    	return $resu;
    }
}